name: win-build

on:
  pull_request:
    paths:
      - "xformers/csrc/**"
      - "third-party/**"
      - ".github/workflows/win-build.yml"
      - "setup.py"
      - "requirements*.txt"

env:
  FORCE_CUDA: 1
  MAX_JOBS: 6
  DISTUTILS_USE_SDK: 1 # otherwise distutils will complain on windows about multiple versions of msvc
  XFORMERS_BUILD_TYPE: "Release"

jobs:
  win_build:
    strategy:
      fail-fast: false
      matrix:
        arch:
          - "8.0"
          - "7.0"
    name: win-build-${{ matrix.arch }}
    runs-on: windows-8-core
    env:
      PY: python3
      TORCH_CUDA_ARCH_LIST: ${{ matrix.arch }}

    timeout-minutes: 360
    defaults:
      run:
        shell: bash
    steps:
      - name: Recursive checkout
        uses: actions/checkout@v3
        with:
          submodules: recursive
          path: "."

      - name: Setup Runner
        uses: ./.github/actions/setup-windows-runner
        with:
          # (FAv2 requires cuda 12+)
          cuda: "12.1.0"
          python: "3.8"

      - name: Install build dependencies
        run: |
          $PY -m pip install wheel setuptools ninja torch==2.1.0 -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu121
          git config --global --add safe.directory "*"
          $PY -c "import torch; print('torch', torch.__version__)"
          $PY -c "import torch; print('torch.cuda', torch.version.cuda)"

      - name: Create sdist
        run: $PY setup.py sdist

      - name: Build from sdist
        run: $PY -m pip install -v dist/*

      - name: Info
        run: |
          cd ../../  # So we don't have a folder named `xformers`
          XFORMERS_MORE_DETAILS=1 $PY -m xformers.info
